package com.aitou.mrylive.presentation.ui.widget;

import android.util.Log;

import com.aitou.mrylive.data.bean.BaseResponse;
import com.aitou.mrylive.data.bean.me.UserInfo;
import com.aitou.mrylive.data.bean.room.RoomAdminInfo;
import com.aitou.mrylive.domain.MeFragmentManager;
import com.aitou.mrylive.presentation.ui.base.BaseObserver;
import com.aitou.mrylive.presentation.ui.base.BasePresenter;

import java.util.List;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by huanzhang on 2016/4/16.
 */
public class UserInfoDialogPresenter extends BasePresenter {
    private IUserInfoDialog mIUser;
    private MeFragmentManager mManager;

    public UserInfoDialogPresenter(IUserInfoDialog uiInterface) {
        super(uiInterface);
        mIUser = uiInterface;
        mManager = new MeFragmentManager();
    }

    public void loadUserInfo(String userId){
        Subscription subscription = mManager.getUserInfo(Integer.parseInt(userId))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<UserInfo>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<UserInfo> response) {
                        mIUser.showUserInfo(response.getData());
                    }
                });
        addSubscription(subscription);
    }
    public void starUser(String token,String uid,String roomid){
        Subscription subscription = mManager.starUsr(token,uid,roomid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        mIUser.showUserInfo(response.getData());
//                        mIUser.getRemoveHitCode(response.getCode());
                        mIUser.getStartCode(response.getCode());
                    }
                });
        addSubscription(subscription);
    }

    public void unStarUser(String token,String uid,String roomid){
        Subscription subscription = mManager.unStarUsr(token,uid,roomid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<String>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
//                        mIUser.showUserInfo(response.getData());
                        mIUser.getRemoveStartCode(response.getCode());
                    }
                });
        addSubscription(subscription);
    }

    public void getAdminList(String token,String uid) {
        Subscription subscription = mManager.getAdmin(token, uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<List<RoomAdminInfo>>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<List<RoomAdminInfo>> response) {
                        mIUser.getAdminLists(response.getData());
                        Log.i("mrl",response.getData().toString()+"正确的的");
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        super.onError(throwable);
                        Log.i("mrl",throwable+"错误的");
                        mIUser.adminnullgoinit();
                    }
                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                        Log.i("mrl","请求完毕ledd");
                        mIUser.adminnullgoinit();
                    }

                    @Override
                    public void onNext(BaseResponse<List<RoomAdminInfo>> response) {
                        super.onNext(response);
                    }

                    @Override
                    protected void onDataFailure(BaseResponse<List<RoomAdminInfo>> response) {
                        super.onDataFailure(response);
                    }
                });
        addSubscription(subscription);
    }

    public void setHit(String token,String hitid){
        Subscription subscription = mManager.setHit(token,hitid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<Object>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mIUser.getHitCode(response.getCode());
                        Log.i("mrl",response.getCode()+"正确的拉黑方式");
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        super.onError(throwable);
                        Log.i("mrl",throwable+" ");
                    }
                });
        addSubscription(subscription);
    }

    public void removeHit(String token,String hitid){
        Subscription subscription = mManager.removeHit(token,hitid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseResponse<Object>>(getUiInterface()) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mIUser.getRemoveHitCode(response.getCode());
                        Log.i("mrl",response.getCode()+"正确的解除拉黑方式");
                    }
                    @Override
                    public void onError(Throwable throwable) {
                        super.onError(throwable);
                        Log.i("mrl",throwable+" ");
                    }
                });
        addSubscription(subscription);
    }

}
